package com.edu.fd2130sprbootdemo.service.impl;

import com.edu.fd2130sprbootdemo.bean.User;
import com.edu.fd2130sprbootdemo.dao.UserMapper;
import com.edu.fd2130sprbootdemo.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: fd2130sprbootdemo
 * @description:
 * @author: Teacher.zhang
 * @create: 2022-03-10 09:27
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(int id) {
        userMapper.deleteByPrimaryKey(id);
    }

    /**
     * 增加
     * @param user
     * @return
     */
    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @Override
    public User selectById(int id) {
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     * 更新
     * @param user
     * @return
     */
    @Override
    public int update(User user) {
        return userMapper.updateByPrimaryKey(user);
    }

    /**
     * 查询全部列表，并且分页
     * @param pageNum 开始页数
     * @param pageSize 每页显示的数据条数
     * @return
     */
    @Override
    public List<User> selectAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return userMapper.selectUsers();
    }
}
